<!--验收页面-->
<template>
    <u-collapse-item :open="true">
        <text slot="title" class="u-page__title">项目验收信息</text>
        <text class="u-collapse-content">
            <view class="common-body-ex">
                <view v-for="(item,index) in formItem" :key="index">
                    <view :class="[['accTime','resourceInTime','firstAcceptTime'].includes(item.value) ? 'add-content' : '']" style="padding:20rpx" v-if="pageList.includes(item.value) && prjType === 'M'">
                        <view class="common-list-ex" style="justify-content: space-between;align-items: center;height: 36rpx">
                            <label style="font-size: 32rpx;"><text class="colorRed">*</text>{{item.label}}:</label>
                            <view style="width: 70%;display: flex;border: 1px solid rgba(228, 228, 228, 1);border-radius: 4rpx;height: 56rpx;align-items: center" :class="item.disable?'disable':'edit'" v-if="prjDetail.type==='todo'">
                                <text space="ensp">{{ "  " }}</text>
                                <image @click="calendar(index)" src="/static/imges/rili.png" mode="" style="width: 26rpx;height: 26rpx;"></image>
                                <text space="ensp">{{ "  " }}</text>
                                <u-input style="margin-top: 2rpx" @click="calendar(index)" v-model="accTimeInfo[item.valueKey]" :disabled="true"
                                         :placeholder="item.disable?'':'请选择相应的日期'"/>
                                <u-calendar v-model="item.show" :mode="mode" @change="(e)=>changeTime(e,index)" :min-date="shijan" :max-date="maxTime"
                                            btn-type="error" active-bg-color="#EB4B4B"/>
                            </view>
                            <view v-else style="font-size: 24rpx">{{accTimeInfo[item.valueKey]}}</view>
                        </view>
                    </view>
                    <view :class="[(index + 1) % 2 !== 0 ? 'add-content' : '']" style="padding:20rpx" v-if="prjType!== 'M'">
                        <view class="common-list-ex" style="justify-content: space-between;align-items: center;height: 36rpx">
                            <label style="font-size: 32rpx;"><text class="colorRed">*</text>{{item.label}}:</label>
                            <view style="font-size: 24rpx">{{accTimeInfo[item.value]}}</view>
                        </view>
                    </view>
                </view>
            </view>
        </text>
    </u-collapse-item>
</template>

<script>
const options = {
    15: [],	// 科技创新
    13: ['firstAcceptTime', 'finalTime'],	// 购置
    21: [],	// 租赁费用
    23: [],	// 维保费用
    11: ['firstAcceptTime', 'finalTime'],	// 套装软件
    12: ['accTime'],	// 自主研发
    14: ['resourceInTime', 'resourceConfirmTime', 'firstAcceptTime', 'finalTime'],	// /工程建设
    22: []	// 外包费用
}
/**
 * 各个阶段对应的编码
 * F4  资源录入
 * F5  资源确认
 * F10 验收申请
 * F11 验收审核
 * F91 初验申请
 * F92 初验审核
 * F93 终验申请
 * F94 终验审核
 */
export default {
    components: {
    },
    props:{
        prjDetail: {
            type: Object,
            required: true,
            default: () => ({})
        },
        prjType: {
            type: String,
            required: true,
        }
    },
    data() {
        return                                           {
            mode: 'date',
            shijan: "",
            maxTime: "2123-01-27",
            formItem: [],
            accTimeInfo:{}
        }
    },
    mounted() {
        this.myDate();
        this.getBtnDisable();
        console.log(this.prjDetail)
        if(this.prjType === 'M'){
            this.accTimeInfo = {
                resourceInTime: '',
                resourceConfirmTime: '',
                endInternalAcceptDate: '',
                firstAcceptTime: '',
                accProInitiationTime: ''
            }
            this.formItem =  [
                {
                    label: '验收时间',
                    value: 'accTime',
                    valueKey:"endInternalAcceptDate",
                    disable:false,
                    show:false
                },
                {
                    label: '资源录入时间',
                    value: 'resourceInTime',
                    valueKey:"resourceInTime",
                    disable:true,
                    show:false
                },
                {
                    label: '资源确认时间',
                    value: 'resourceConfirmTime',
                    valueKey:"resourceConfirmTime",
                    disable:true,
                    show:false
                },
                {
                    label: '初验时间',
                    value: 'firstAcceptTime',
                    valueKey:"firstAcceptTime",
                    disable:true,
                    show:false
                },
                {
                    label: '终验时间',
                    value: 'finalTime',
                    valueKey:"endInternalAcceptDate",
                    disable:true,
                    show:false
                }
            ];
            this.getAccTimeM();
        }else{
            this.accTimeInfo = {
                realStartTime: '',
                realEndTime: '',
                resourceInTime: '',
                resourceConfirmTime: '',
                endInternalAcceptDate: '',
                jiaofuApplicationDate: '',
                maintainDate: '',
                rentableOperateTime:'',
            }
            this.getFormItem();
            this.getAccTime();
        }
    },
    computed:{
        pageList() {
            return options[this.prjDetail.pageType] || []
        },
    },
    methods:{
        getFormItem(){
            if(this.prjDetail.manageMode === '01'){
                this.formItem=[
                    {
                        label: '实际开工时间',
                        value: 'realStartTime'
                    },
                    {
                        label: '实际完工时间',
                        value: 'realEndTime'
                    },
                    {
                        label: '资源录入时间',
                        value: 'resourceInTime'
                    },
                    {
                        label: '资源确认时间',
                        value: 'resourceConfirmTime'
                    },
                    {
                        label: '内部验收时间',
                        value: 'endInternalAcceptDate'
                    },
                    {
                        label: '交付申请时间',
                        value: 'jiaofuApplicationDate'
                    },
                    {
                        label: '交维结束时间',
                        value: 'maintainDate'
                    },
                ];
            }else{
                this.formItem=[
                    {
                        label: '实际开工时间',
                        value: 'realStartTime'
                    },
                    {
                        label: '实际完工时间',
                        value: 'realEndTime'
                    },
                    {
                        label: '内部验收时间',
                        value: 'endInternalAcceptDate'
                    },
                ];
            }
            //单站项目 智联代建、服务成本类项目 软件开发父项目、仅无实施流程的智联代建、服务成本整体父项目显示 该字段显示可起租条件
            //和PC保持一致，单站、整体智联业务常显示　或　智联单项目核算服务成本的购买服务类显示
            console.log(111,this.getShowRent())
            if(this.getShowRent()){
                console.log(123)
                this.formItem.push({
                    label: '具备可起租条件',
                    value: 'rentableOperateTime'
                })
            }
        },
        getShowRent(){
            console.log(234,this.prjDetail.manageMode,this.prjDetail.isNewbusiness)
            let flag = this.prjDetail.manageMode === '01' && this.prjDetail.prjType === 'W' && this.prjDetail.buildModes === '25' && this.prjDetail.isSingleAccounting === '1'
            return ( ['01','03'].includes(this.prjDetail.manageMode) && this.prjDetail.isNewbusiness === '1') || flag
        },
        //根据当前阶段判断
        // 自主研发 F10 验收申请 F11 验收审核 验收时间一直可编辑
        // F91 初验申请 F92 初验审核  初验时间可编辑  F93 终验申请 F94 终验审核 终验时间可编辑
        getBtnDisable(){
            if(this.prjDetail.type === 'todo'){
                if(['F91','F92'].includes(this.prjDetail.btnType)){
                    this.formItem.forEach((item)=>{
                        item.disable = item.value !== 'firstAcceptTime';
                    })
                }else if(['F93','F94'].includes(this.prjDetail.btnType)){
                    this.formItem.forEach((item)=>{
                        item.disable = item.value !== 'finalTime';
                    })
                }else{
                    console.log('保持原定义数据，不做处理')
                }

            }else{
                this.formItem.forEach((item)=>{
                    item.disable=true;
                })
            }
        },
        //获取当前系统时间
        myDate() {
            let date = new Date();
            date.setDate(date.getDate());
            let yue = (date.getMonth() + 1 / 1) > 9 ? (date.getMonth() + 1 / 1) : ("0" + (date.getMonth() + 1 / 1));
            let geate = date.getDate();
            let str = date.getFullYear() + '-' + yue + '-' + geate;
            this.maxTime = str;
        },
        //点击时间图标 显示日历选择器
        calendar(index) {
            if(!this.formItem[index].disable){
                this.formItem[index].show = true;
            }
        },
        // 改变时间触发事件
        changeTime(e,index) {
            this.accTimeInfo[this.formItem[index].value] = e.result
            let obj={
                code:this.formItem[index].value,
                value:this.accTimeInfo[this.formItem[index].value]
            }
            console.log(obj)
        },
        // 信息化 获取验收相关时间
        getAccTimeM() {
            this.$axios.get('/acceptance/api/accept/itAcceptance/getItAcceptAllTime?prjId='+this.prjDetail.prjId).then((res)=>{
                for (const i in res.data) {
                    this.$set(this.accTimeInfo, i, res.data[i])
                }
                this.$nextTick(() => {
                    const url=window.location.protocol+'//'+window.location.host;
                    window.parent.postMessage({ type: 'acceptanceHeight',height: document.getElementById('zrAcceptanceInfo').clientHeight }, url)
                    console.log('发送高度',document.getElementById('zrAcceptanceInfo').clientHeight)
                })
            })
            // 获取最后节点时间
            this.$axios.get('/acceptance/api/accept/itAcceptance/getAcceptProcessInitiationTime?prjId='+this.prjDetail.prjId).then((res)=>{
                for (const i in res.data) {
                    this.accTimeInfo.accProInitiationTime = res.data || new Date()
                }
            })
        },
        getAccTime(){
            this.$axios.get('/acceptance/api/accept/commonAcceptance/getAcceptAllTime?prjId='+this.prjDetail.prjId).then((res)=>{
                this.accTimeInfo=res.data;
            })
        }
    }
}
</script>

<style>@import "@/common/common-ui.css";</style>
<style>@import "@/common/uView.css";</style>
<style scoped lang="scss">
.add-content{
    background: #efefef;
}
.disable{
    background-color: #efefef;
}
.edit{
    background-color: #FFFFFF;
}
</style>